
package tkatva.consulting.jmxpoller.smxService

import tkatva.consulting.jmxconnection.beans._
import tkatva.consulting.jmxpoller.JmxPoller
import tkatva.consulting.jmxpoller.CfgHelper
/*
 * Author Tuomas Katva
 * 
 * This class is the service class to retrieve information 
 * on ServiceMix and control Camel routes
 * 
 */

class SmxService (val smxUrlParam : String) {
  
  
    var smxUrl : String = smxUrlParam
    var adminUsr : String = null
    var adminPword : String = null
    
    var jmxser = new JmxPoller
    jmxser.srvUrl = smxUrl
    
    def loginSmxMonitor(adminUsrParam : String,adminPwordParam : String) : Boolean = {
      
      var filePath = ClassLoader.getSystemResource("cfg.xml").getFile()
      var cfg = new CfgHelper
      var adminCred = cfg.getLoginUsrNameAndPword(filePath)
      if (adminUsrParam.trim.equals(adminCred._1.trim) && adminPwordParam.trim.equals(adminCred._2.trim)) {
        adminUsr = adminCred._1
        adminPword = adminCred._2
        return true
      } else {
        return false
      
      }
    
    }
    
   def getSmxBeans() : List[JmxBean] = {
     if (adminUsr != null && adminPword != null) {
     var filePath = ClassLoader.getSystemResource("cfg.xml").getFile()
     var cfg = new CfgHelper
     var filters = cfg.getFilters(filePath)
     var jbeans = jmxser.getSpecifiedBeans(filters)
     return jbeans
     } else {
       return null
     }
   }
  
  
  
  
}
